package com.control.qct.businesssteward.adapter;

import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.control.qct.businesssteward.R;
import com.control.qct.businesssteward.model.TakeDeliveryListModel;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * Created by Administrator on 2018/1/9 0009.
 */

public class TakeDeliveryListAdapter extends BaseQuickAdapter<TakeDeliveryListModel, BaseViewHolder> {
    public TakeDeliveryListAdapter(@Nullable List<TakeDeliveryListModel> data) {
        super(R.layout.rv_take_delivery_list_item, data);
    }

    @Override
    protected void convert(final BaseViewHolder holder, TakeDeliveryListModel item) {
        holder.setText(R.id.tv_receipts_code, "单据编号：" + item.getOrderCode()).setText(R.id
                .tv_receipts_date, item.getDate());
        switch (item.getStatus()) {
            case 0:
                holder.setText(R.id.tv_receipts_status, "待收货");
                break;
            case 1:
                holder.setText(R.id.tv_receipts_status, "已发货");
                break;
            case 2:
                holder.setText(R.id.tv_receipts_status, "差异");
                break;
        }
        RecyclerView rvOrderGoods = holder.getView(R.id.rv_receipts_goods);
        rvOrderGoods.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false));
        OrderGoodsAdapter orderGoodsAdapter = new OrderGoodsAdapter(item.getGoodsPictureList());
        rvOrderGoods.setAdapter(orderGoodsAdapter);
        orderGoodsAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                if (mICallbackClickListener != null) {
                    mICallbackClickListener.onClickListener(holder.getAdapterPosition());
                }
            }
        });


    }

    class OrderGoodsAdapter extends BaseQuickAdapter<Integer, BaseViewHolder> {

        public OrderGoodsAdapter(@Nullable List<Integer> data) {
            super(R.layout.rv_order_goods_item, data);
        }

        @Override
        protected void convert(BaseViewHolder holder, Integer item) {
            holder.setImageResource(R.id.iv_goods_picture, item);
        }
    }

    private ICallbackClickListener mICallbackClickListener;

    public void setCallbackClickListener(ICallbackClickListener listener) {
        this.mICallbackClickListener = listener;
    }

    public interface ICallbackClickListener {
        void onClickListener(int position);
    }
}
